package com.fl.nettydemo.c2;

import io.netty.channel.DefaultEventLoop;
import io.netty.channel.nio.NioEventLoopGroup;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

@Slf4j
public class TestEventLoop {
    public static void main(String[] args) {
        NioEventLoopGroup group = new NioEventLoopGroup(3); //IO事件 普通事件 定时i任务
        DefaultEventLoop eventLoop = new DefaultEventLoop(); //普通事件 定时i任务
        System.out.println(group.next());
        System.out.println(group.next());
        System.out.println(group.next());
        System.out.println(group.next());
        //普通任务
        group.next().submit(()->{
            try {
                Thread.sleep(1000);
                log.info("执行任务:->{}",Thread.currentThread().getName());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        // 定时任务  执行频率0立马执行 1秒钟运行一次
        group.next().scheduleAtFixedRate(()->{
            log.info("ok");
        },0,1,TimeUnit.SECONDS);
    }
}
